package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.service.WorkSpaceService;
import com.sky.vo.BusinessDataVO;
import com.sky.vo.DishOverViewVO;
import com.sky.vo.OrderOverViewVO;
import com.sky.vo.SetmealOverViewVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

@RestController
@RequestMapping("/admin/workspace")
@Slf4j
public class WorkSpaceController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private WorkSpaceService workSpaceService;

    /**
     * 获取营业数据
     * @return
     */

    @GetMapping("/businessData")
    public Result<BusinessDataVO> getBusinessData(){
        log.info("获取营业数据");
        LocalDate time = LocalDate.now();
        LocalDateTime endTime = LocalDateTime.of(time, LocalTime.MAX);
        LocalDateTime beginTime = LocalDateTime.of(time, LocalTime.MIN);
        BusinessDataVO businessDataVO = orderService.getBusinessData( endTime, beginTime);
        return Result.success(businessDataVO);
    }

    /**
     * 获取订单统计数据
     */

    @GetMapping("/overviewOrders")
    public Result<OrderOverViewVO> getOverViewOrders(){
        log.info("获取订单统计数据");
        OrderOverViewVO orderOverViewVO = workSpaceService.getOverViewOrders();
        return Result.success(orderOverViewVO);
    }

    /**
     * 查询菜品总览
     * @return
     */

    @GetMapping("/overviewDishes")
    public Result<DishOverViewVO> getOverViewDishes(){
        log.info("查询菜品总览");
        DishOverViewVO dishOverViewVO = workSpaceService.getOverViewDishes();
        return Result.success(dishOverViewVO);

    }

    /**
     * 查询套餐总览查询套餐总览
     */
    @GetMapping("/overviewSetmeals")
    public Result<SetmealOverViewVO> getOverViewSetmeals(){
        log.info("查询套餐总览");
        SetmealOverViewVO setmealOverViewVO = workSpaceService.getOverViewSetmeals();
        return Result.success(setmealOverViewVO);
    }
}
